#!/bin/bash

userName=`whoami` ##用户名
version=$1 ## 版本
cerkey="iPhone Developer: zhibin Wang (8QX34UNN59)"  ##证书
key=68711df1-f9ce-46cb-93fd-f23a634ad7b5 ##
timepack=`date '+%Y%m%d%H%M%S'`
tag=$3
branch=$2
codePath=/Users/${userName}/workspace/iiappleiosclient
projectPath=/Users/${userName}/workspace/iiappleiosclient/AppInstallerGreen/AppInstallerGreen.xcworkspace  ##代码地址
#projectPath=/Users/${userName}/project/AppInstallerGreen/AppInstallerGreen.xcworkspace  ##代码地址
buildPath=/Users/${userName}/workspace/workCodes/socket/Applications/build
downPath=/Users/${userName}/workspace/workCodes/upload/package

jfaxib=/Users/${userName}/Documents/JFAPods/jfaxib
jfamodules=/Users/${userName}/Documents/JFAPods/jfamodules
jfacommons=/Users/${userName}/Documents/JFAPods/jfacommons
 
array=($jfaxib $jfamodules $jfacommons)

for i in ${array[@]} 
do
	cd $i
	git pull
done


cd $codePath
git checkout $branch
git pull origin $branch

cd AppInstallerGreen

pod install

xcodebuild clean -workspace "$projectPath" -scheme AppInstallerGreen -configuration $version CONFIGURATION_BUILD_DIR="$buildPath"

xcodebuild -workspace "$projectPath" -scheme AppInstallerGreen -configuration $version CONFIGURATION_BUILD_DIR="$buildPath"

xcrun -sdk iphoneos PackageApplication -v  ${buildPath}/AppInstallerGreen.app -o ${downPath}/iiapple.${timepack}.ipa

echo iiapple.${timepack}.ipa > $downPath/iiapplefilename
